package com.szholly.data.general.interceptor.defulat;

import java.util.List;

import com.szholly.data.coderule.RuleService;
import com.szholly.data.general.*;
import com.szholly.data.general.interceptor.*;

/**
 * 定义代码表缓存拦截接口
 */
public class CodeRuleDbInterceptor extends DbEditInterceptorClass {

	public CodeRuleDbInterceptor() {
		super.setIndex(-100);
	}

	public String getInterceptorName() {
		return "保存前的的编码规则调用";
	}

	@SuppressWarnings("rawtypes")
	@Override
	public void BeforeDbEditOption(ITable table, Object editEntitys,
			DbEditType editType) {
		if (editType == DbEditType.Insert) {
			if(editEntitys instanceof RowBase){
				RuleService.FillRuleCode(table, (RowBase) editEntitys, null);
			}else if(editEntitys instanceof List){
				List entityList = (List)editEntitys;
				for(Object item : entityList){
					if(item instanceof RowBase){
						RuleService.FillRuleCode(table, (RowBase) item, null);
					}
				}
			}
		}
	}

	@Override
	public void DbEditOptionException(ITable table, Object editEntitys,
			DbEditType editType, Exception ex) {

	}

	@Override
	public void AfterDbEditOption(ITable table, Object editEntitys,
			DbEditType editType) {

	}
}
